<?php

// data types
const TYPE_INT = 3;
const TYPE_FLOAT = 4;
const TYPE_VARCHAR = 253;
const TYPE_CHAR = 254;

const DBPATH = "d:\\wwwroot\\hr\\data";
const USER = "";
const PASSWORD = "";
const DBNAME = "nexans";

// set default timezone
date_default_timezone_set('Asia/Shanghai');

function FormatDate($str)
{
    try {
        $date = new DateTime($str);
    } 
    catch (Exception $e) {
        return NULL;
    }

    return $date->format("Y-m-d");
}

function Valid_Client()
{
    if ($_SERVER["REMOTE_ADDR"] != "127.0.0.1")
        die("Fatal Error: Permission denied");
}

function GetDB()
{
    $db = new SQLite3(DBPATH .  "\\" . DBNAME . ".db3");
    return $db;
}

function GetEmInfoList($db)
{
    $lstEmInfo = array();

    $sqlstr = "select em_id, em_name from eminfo_v order by em_id";
    if ($result = $db->query($sqlstr)) {
        while($row = $result->fetchArray()) {
            $lstEmInfo[] = $row;
        }
    }
    return $lstEmInfo;
}

function GetVatypeList($db)
{
    $lstEmInfo = array();

    $sqlstr = "select type_id, type_text from vatype_t order by type_id";
    if ($result = $db->query($sqlstr)) {
        while($row = $result->fetchArray()) {
            $lstEmInfo[] = $row;
        }
    }
    return $lstEmInfo;
}

function GetDepartList($db)
{
    $lstEmInfo = array();

    $sqlstr = "select depart_id, depart_name from depart_t order by depart_id";
    if ($result = $db->query($sqlstr)) {
        while($row = $result->fetchArray()) {
            $lstEmInfo[] = $row;
        }
    }
    return $lstEmInfo;
}

?>
